package com.zengdada.authority.exception;


import com.zengdada.authority.config.listener.AuthorityEnvironmentPreparedEvent;

/**
 * @Auther: 12614
 * @Contact: 1261438511@qq.com
 * @Date: 2018/11/13 15:42
 * @Description:
 */
public class RoutineException extends RuntimeException {
    private String message;
    private int code;

    public RoutineException() {
        super();
    }

    public RoutineException(String message, Throwable cause) {
        super(message, cause);
        this.message = message;
    }


    public RoutineException(String message, int code) {
        super(message);
        this.code = code;
        this.message = message;
    }


    public RoutineException(String message) {
        super(message);
        this.message = message;
    }

    @Override
    public String getMessage() {
        String message = this.message;
        if (AuthorityEnvironmentPreparedEvent.profiles_active != null && !AuthorityEnvironmentPreparedEvent.profiles_active.contains("dev"))
            message = (message != null ? message.substring(0, message.length() > 150 ? 149 : message.length()) : "");
        return message;
    }

    public int getCode() {
        return code;
    }

    protected RoutineException(String message, Throwable cause,
                               boolean enableSuppression,
                               boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);
    }
}
